package com.ymatou.iapi.login.testcase;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.login.parameter.BindWeiXinUseroRequestDtoBean;
import com.ymatou.iapi.login.parameter.UnBindThirdPartyAccountDtoBean;
import com.ymatou.iapi.login.parameter.WxUserLoginBean;
import com.ymatou.iapi.login.parameter.WxWapLoginBean;
import com.ymatou.iapi.login.service.BindWeiXinUseroRequestDtoCall;
import com.ymatou.iapi.login.service.UnBindThirdPartyAccountDtoCall;
import com.ymatou.iapi.login.service.WxWapLoginCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.enums.AppSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.TerminalSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.ThirdPartyTypeEnum;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.LoginLog;
import com.ymttest.database.model.ThirdpartyUserbind;
import com.ymttest.database.model.ThirdpartyUserbindHistory;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ThirdPartyType;
/**
*微信公众号登录（全球优选）
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_WxWapLogin{
	private static WxWapLoginBean wxwaploginBean;
	private static WxWapLoginCall wxwaploginCall;
	private static  JUserWapper ju ;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("微信公众号登录（全球优选）");
	}

	@Before
	public void caseUp() {
		wxwaploginBean=new WxWapLoginBean();
		wxwaploginCall=new WxWapLoginCall();
		ju=new JUserWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(wxwaploginCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void verifyDBBind(Integer uid, WxWapLoginBean cq) {
		Logger.comment("验证thirdparty_userbind");
		ThirdpartyUserbind thirdinfo = ju.selectthirdpartyuserbind(uid).get(0);
		Logger.verifyEquals(cq.getUnionId(), thirdinfo.getThirdPartyId(), "验证ThirdPartyId");
		Logger.verifyEquals(ThirdPartyTypeEnum.WeiXin.getCode(), thirdinfo.getThirdPartyType(), "验证ThirdPartyType");
		
		
	}

	private void verifyDB(Integer uid, WxWapLoginBean cq) throws InterruptedException {
		Logger.comment("验证thirdparty_userbind");
		ThirdpartyUserbind thirdinfo = ju.selectthirdpartyuserbind(uid).get(0);
		Logger.verifyEquals(cq.getUnionId(), thirdinfo.getThirdPartyId(), "验证ThirdPartyId");
		Logger.verifyEquals(ThirdPartyTypeEnum.WeiXin.getCode(), thirdinfo.getThirdPartyType(), "验证ThirdPartyType");

		Logger.comment("验证thirdparty_userbind_history");
		ThirdpartyUserbindHistory thirdinfohist = ju.selectthirdpartyuserbindhistory(uid).get(0);
		Logger.verifyEquals(true, thirdinfohist.getBinding(), "验证binding状态");
		
		Logger.verifyEquals(AppSourceEnum.GlobalWxWap.getCode(), thirdinfohist.getAppSource(), "验证AppSource");
		Logger.verifyEquals(cq.getClientIp(), thirdinfohist.getClientIp(), "验证ClientIp");
		Logger.verifyEquals(cq.getDeviceId(), thirdinfohist.getDeviceId(), "验证DeviceId");
		Logger.verifyEquals(cq.getTerminalSource(), thirdinfohist.getTerminalSource(), "验证TerminalSource");

		Logger.verifyEquals(cq.getOpenId(), thirdinfohist.getOpenId(), "验证OpenId");
		Logger.verifyEquals(cq.getHeadImgUrl(), thirdinfohist.getHeadimgurl(), "验证Headimgurl");
		
		LoginLog loginLog = new JUserWapper().selectLastLoginLogByUid(uid).get(0);
		Logger.verifyEquals(wxwaploginCall.getJsonObject().get("data").getAsJsonObject().get("loginId").getAsString(), loginLog.getLoginId(), "验证LoginLog表中LoginId");
		Logger.verifyEquals(cq.getClientIp(), loginLog.getClientIp(), "验证LoginLog表中ClientIp");
		// wx登入6
		Logger.verifyEquals(6, loginLog.getChannelSource(), "验证LoginLog表中ChannelSource");
		Logger.verifyEquals(cq.getDeviceId(), loginLog.getDeviceId(), "验证LoginLog表中DeviceId");
		Logger.verifyNotNull(loginLog.getServerIP(), "验证LoginLog表中ServerIP");

		if (wxwaploginCall.getString("code").equals("200")) {
			Logger.verifyIsContains("成功", loginLog.getResponseDesc(), "验证LoginLog表中ResponseDesc");
			Logger.verifyEquals(200, loginLog.getResponseCode(), "验证LoginLog表中ResponseCode");
		} 
		Logger.verifyEquals(0, loginLog.getUserSystem(), "验证LoginLog表中UserSystem");
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_WxWapLogin_001() {
		//201908 渠道变更 GlobalWxWap
		Logger.start(true,"手机号已存在微信公众号登录（全球优选）,成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer userId=registerResult.get("UserId").getAsInt();
			BindWeiXinUseroRequestDtoBean bean=JUserCallService.initBindWeiXinUseroRequestDtoBean(token);
			bean.getWeiXinUser().setRegSource(AppSourceEnum.GlobalWxWap);
			BindWeiXinUseroRequestDtoCall wx = JUserCallService.bindWeiXinUseroRequestDto(bean);
			JUserWapper JUserWapper=new JUserWapper();
			List<ThirdpartyUserbind> list = JUserWapper.selectthirdpartyuserbind(userId).stream().filter(tu->{return tu.getAppSource()==AppSourceEnum.GlobalWxWap.getCode();}).collect(Collectors.toList());
			Logger.verifyEquals(1, list.size(), "验证有绑定记录");
			wxwaploginBean.setClientPort("901");
			wxwaploginBean.setClientIp(regbean.getClientIp());
			wxwaploginBean.setDeviceId(regbean.getDeviceId());
			wxwaploginBean.setMobile(regbean.getLoginMobile());
			wxwaploginBean.setOpenId(bean.getWeiXinUser().getOId());
			wxwaploginBean.setTerminalSource(TerminalSourceEnum.Android.getCode());
			wxwaploginBean.setUnionId(bean.getWeiXinUser().getUnionId());
			wxwaploginCall.setData(wxwaploginBean);
			wxwaploginCall.callService();	
			Logger.verifyEquals("200", wxwaploginCall.getString("code"), "验证code");
			Logger.verifyNotEquals(token, wxwaploginCall.getToken(), "验证新生成的token");
			Map sign=AuthCallServiceV2.signAuth(wxwaploginCall.getToken());
//			Logger.comment(sign.toString());
			Logger.verifyEquals(userId, sign.get("userId"), "验证token-UserId");
			Logger.verifyEquals(userId, wxwaploginCall.getUserId(), "验证UserId");
			Logger.verifyEquals(regbean.getLoginId(), wxwaploginCall.getLoginId(), "验证LoginId");
			list = JUserWapper.selectthirdpartyuserbind(userId).stream().filter(tu->{return tu.getAppSource()==AppSourceEnum.GlobalWxWap.getCode();}).collect(Collectors.toList());
			Logger.verifyEquals(1, list.size(), "验证有绑定记录");
			Logger.debug(FormatUtil.beanToGSONString(list));
			Logger.verifyEquals(AppSourceEnum.GlobalWxWap.getCode(), list.get(0).getAppSource(), "验证AppSource");
			Logger.verifyEquals(wxwaploginBean.getUnionId(), list.get(0).getThirdPartyId(), "验证thirdPartyId");
			Logger.verifyEquals(wxwaploginBean.getOpenId(), list.get(0).getOpenId(), "验证openId");
			Logger.verifyEquals(6, list.get(0).getThirdPartyType(), "验证thirdPartyType");
			Logger.verifyEquals(userId, list.get(0).getUserId(), "验证userId");
			LoginLog loginLog = new JUserWapper().selectLastLoginLogByUid(userId).get(0);
			Logger.debug(FormatUtil.beanToGSONString(loginLog));
			Logger.verifyEquals(wxwaploginBean.getClientPort(), loginLog.getClientPort(), "验证LoginLog表中getClientPort");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxWapLogin_002() {
		Logger.start(true,"GlobalHunterWap已绑定uid不输入手机号微信公众号登录（全球优选）,成功");
		try {
			//201908 渠道变更 使用存量数据不会再新创建绑定关系了
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer userId=registerResult.get("UserId").getAsInt();
			BindWeiXinUseroRequestDtoBean bean=JUserCallService.initBindWeiXinUseroRequestDtoBean(token);
			bean.getWeiXinUser().setRegSource(AppSourceEnum.App);
			BindWeiXinUseroRequestDtoCall wx = JUserCallService.bindWeiXinUseroRequestDto(bean);
			JUserWapper JUserWapper=new JUserWapper();
			List<ThirdpartyUserbind> list = JUserWapper.selectthirdpartyuserbind(userId).stream().filter(tu->{return tu.getAppSource()==AppSourceEnum.App.getCode();}).collect(Collectors.toList());
			Logger.verifyEquals(1, list.size(), "验证有绑定记录");
			//第一次绑定
			wxwaploginBean.setClientIp(regbean.getClientIp());
			wxwaploginBean.setDeviceId(regbean.getDeviceId());
			wxwaploginBean.setMobile(regbean.getLoginMobile());
			wxwaploginBean.setOpenId(bean.getWeiXinUser().getOId());
			wxwaploginBean.setTerminalSource(TerminalSourceEnum.Android.getCode());
			wxwaploginBean.setUnionId(bean.getWeiXinUser().getUnionId());
			wxwaploginCall.setData(wxwaploginBean);
			wxwaploginCall.callService();	
			Logger.verifyEquals("200", wxwaploginCall.getString("code"), "验证code");
			
			wxwaploginBean.setMobile(null);
			wxwaploginCall.callService();	
			Logger.verifyEquals("200", wxwaploginCall.getString("code"), "验证code");
			
			Logger.verifyNotEquals(token, wxwaploginCall.getToken(), "验证新生成的token");
			Map sign=AuthCallServiceV2.signAuth(wxwaploginCall.getToken());
//			Logger.comment(sign.toString());
			Logger.verifyEquals(userId, sign.get("userId"), "验证token-UserId");
			Logger.verifyEquals(userId, wxwaploginCall.getUserId(), "验证UserId");
			Logger.verifyEquals(regbean.getLoginId(), wxwaploginCall.getLoginId(), "验证LoginId");
			list=JUserWapper.selectthirdpartyuserbind(userId);
			Logger.debug("selectthirdpartyuserbind:"+FormatUtil.beanToGSONString(list));
//			list =list.stream().filter(tu->{return tu.getAppSource()==AppSourceEnum.GlobalWxWap.getCode();}).collect(Collectors.toList());
			Logger.verifyEquals(1, list.size(), "验证有绑定记录");
			Logger.debug(FormatUtil.beanToGSONString(list));
			Logger.verifyEquals(AppSourceEnum.App.getCode(), list.get(0).getAppSource(), "验证AppSource");
			Logger.verifyEquals(wxwaploginBean.getUnionId(), list.get(0).getThirdPartyId(), "验证thirdPartyId");
			Logger.verifyEquals(wxwaploginBean.getOpenId(), list.get(0).getOpenId(), "验证openId");
			Logger.verifyEquals(6, list.get(0).getThirdPartyType(), "验证thirdPartyType");
			Logger.verifyEquals(userId, list.get(0).getUserId(), "验证userId");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_WxWapLogin_003() {
		Logger.start(true,"不输入uid失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer userId=registerResult.get("UserId").getAsInt();
			BindWeiXinUseroRequestDtoBean bean=JUserCallService.initBindWeiXinUseroRequestDtoBean(token);
			bean.getWeiXinUser().setRegSource(AppSourceEnum.App);
			BindWeiXinUseroRequestDtoCall wx = JUserCallService.bindWeiXinUseroRequestDto(bean);
			
			wxwaploginBean.setClientIp(regbean.getClientIp());
			wxwaploginBean.setDeviceId(regbean.getDeviceId());
//			wxwaploginBean.setMobile(regbean.getLoginMobile());
			wxwaploginBean.setOpenId(bean.getWeiXinUser().getOId());
			wxwaploginBean.setTerminalSource(TerminalSourceEnum.Android.getCode());
//			wxwaploginBean.setUnionId(bean.getWeiXinUser().getUnionId());
			wxwaploginCall.setData(wxwaploginBean);
			wxwaploginCall.callService();	
			Logger.verifyEquals("400", wxwaploginCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	//20190904 增加WxWapLogin 注册流程
	public void Tc_WxWapLogin_004() {
//		Logger.start(true,"输入uid和手机号都不存在,登入失败");
		Logger.start(true,"输入uid和手机号都不存在,创建新用户");
		try {
			
			String moblie = TestDataManager.getPhoneNum();
			if (JUserCallService.mobileExists(moblie)) {
				moblie = TestDataManager.getPhoneNum();
			}
			
			wxwaploginBean.setClientIp(TestDataManager.getRandomUUID().toString());
			wxwaploginBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			wxwaploginBean.setMobile(moblie);
			wxwaploginBean.setOpenId("oid"+TestDataManager.getRandomNum(8));
			wxwaploginBean.setTerminalSource(TerminalSourceEnum.Android.getCode());
			wxwaploginBean.setUnionId("uid"+TestDataManager.getRandomNum(8));
			wxwaploginCall.setData(wxwaploginBean);
			wxwaploginCall.callService();	
			Logger.verifyEquals("200", wxwaploginCall.getString("code"), "验证code");
			Integer uid=wxwaploginCall.getJsonObject().get("data").getAsJsonObject().get("userId").getAsInt();
			verifyDB(uid, wxwaploginBean);
			verifyDBBind(uid, wxwaploginBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxWapLogin_005() {
		Logger.start(true,"用户未绑定过微信登入微信公众号登录（全球优选）,成功,码头账户不会显示微信绑定");
		try {
			//201908 微信公众号登录视为码头绑定关系
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer userId=registerResult.get("UserId").getAsInt();
			
			wxwaploginBean.setClientIp(regbean.getClientIp());
			wxwaploginBean.setDeviceId(regbean.getDeviceId());
			wxwaploginBean.setMobile(regbean.getLoginMobile());
			wxwaploginBean.setOpenId("oid"+TestDataManager.getRandomNum(8));
			wxwaploginBean.setTerminalSource(TerminalSourceEnum.Android.getCode());
			wxwaploginBean.setUnionId("uid"+TestDataManager.getRandomNum(8));
			wxwaploginCall.setData(wxwaploginBean);
			wxwaploginCall.callService();	
			Logger.verifyEquals("200", wxwaploginCall.getString("code"), "验证code");
			JsonObject result = JUserCallService.SingleWeiXinBriefInfoCall(userId, null);
			Logger.verifyEquals("null",result.get("WeiXinNickName").toString().toLowerCase(), "验证没有微信信息");
			String needbind=JUserCallService.CheckThirdPartyUserIsRealNeedBindMobile(wxwaploginBean.getUnionId(), ThirdPartyTypeEnum.WeiXin.toString());
			Logger.verifyEquals("no",needbind.toLowerCase(), "验证微信uid绑定码头用户");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxWapLogin_006() {
		Logger.start(true,"码头微信解绑会影响微信公众号登录（全球优选）绑定关系");
		try {
			//201908 解绑微信会影响微信公众号登录（全球优选）
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer userId=registerResult.get("UserId").getAsInt();
			Thread.sleep(1000);
			BindWeiXinUseroRequestDtoBean bean=JUserCallService.initBindWeiXinUseroRequestDtoBean(token);
			bean.getWeiXinUser().setRegSource(AppSourceEnum.App);
			BindWeiXinUseroRequestDtoCall wx = JUserCallService.bindWeiXinUseroRequestDto(bean);
			Thread.sleep(1000);
			JUserWapper JUserWapper=new JUserWapper();
			List<ThirdpartyUserbind> list = JUserWapper.selectthirdpartyuserbind(userId).stream().filter(tu->{return tu.getAppSource()==AppSourceEnum.App.getCode();}).collect(Collectors.toList());
			Logger.verifyEquals(1, list.size(), "验证有绑定记录");
			Thread.sleep(1000);
			wxwaploginBean.setClientIp(regbean.getClientIp());
			wxwaploginBean.setDeviceId(regbean.getDeviceId());
			wxwaploginBean.setMobile(regbean.getLoginMobile());
			wxwaploginBean.setOpenId(bean.getWeiXinUser().getOId());
			wxwaploginBean.setTerminalSource(TerminalSourceEnum.Android.getCode());
			wxwaploginBean.setUnionId(bean.getWeiXinUser().getUnionId());
			wxwaploginCall.setData(wxwaploginBean);
			wxwaploginCall.callService();	
			Logger.verifyEquals("200", wxwaploginCall.getString("code"), "验证code");
			Integer uid=wxwaploginCall.getJsonObject().get("data").getAsJsonObject().get("userId").getAsInt();
			//这里做一次解绑
			UnBindThirdPartyAccountDtoBean  unBindThirdPartyAccountDtoBean  = JUserCallService.initUnBindThirdPartyAccountDtoBean(bean.getWeiXinUser().getUnionId(), ThirdPartyType.WEIXIN, userId);
			UnBindThirdPartyAccountDtoCall  unBindThirdPartyAccountDtoCall  = JUserCallService.unBindThirdPartyAccountDto(unBindThirdPartyAccountDtoBean);
			 list = JUserWapper.selectthirdpartyuserbind(userId).stream().filter(tu->{return tu.getAppSource()==AppSourceEnum.App.getCode();}).collect(Collectors.toList());
			Logger.verifyEquals(0, list.size(), "验证解绑记录");
			
			//微信公众号登录受影响
			wxwaploginBean.setMobile(TestDataManager.getPhoneNum());
			wxwaploginCall.callService();	
			Logger.verifyEquals("200", wxwaploginCall.getString("code"), "验证code");
			Integer uid2=wxwaploginCall.getJsonObject().get("data").getAsJsonObject().get("userId").getAsInt();
			//TODO 要修改 没有手机号不能注册成功
			Logger.verifyNotEquals(uid, uid2, "解绑成功生成新用户");
			//{"code":21,"message":"用户未找到","data":null}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxWapLogin_007() {
		Logger.start(true,"手机号已存在微信公众号登录（全球优选）,然后换一个微信uid登入,更新uid信息,不更新头像昵称");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer userId=registerResult.get("UserId").getAsInt();
			
			
//			UserRegisterInfoRequestDtoBean regbean2 = JUserCallService.initUserRegisterInfoRequestDtoBean();
//			UserRegisterInfoRequestDtoCall urrc2 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean2);
//			
//			JsonObject registerResult2 = urrc2.getJsonObject().get("Result").getAsJsonObject();
//			String token2=registerResult2.get("Token").getAsString();
//			Integer userId2=registerResult2.get("UserId").getAsInt();
			//第一次绑定
			wxwaploginBean.setClientIp(regbean.getClientIp());
			wxwaploginBean.setDeviceId(regbean.getDeviceId());
			wxwaploginBean.setMobile(regbean.getLoginMobile());
			wxwaploginBean.setOpenId("oid"+TestDataManager.getRandomIntNum(8));
			wxwaploginBean.setTerminalSource(TerminalSourceEnum.Android.getCode());
			wxwaploginBean.setUnionId("uid"+TestDataManager.getRandomIntNum(8));
			wxwaploginCall.setData(wxwaploginBean);
			wxwaploginCall.callService();	
			Logger.verifyEquals("200", wxwaploginCall.getString("code"), "验证code");
			wxwaploginBean.setOpenId("oid"+TestDataManager.getRandomIntNum(8));
			wxwaploginBean.setUnionId("uid"+TestDataManager.getRandomIntNum(8));
			wxwaploginCall.callService();	
			Logger.verifyEquals("200", wxwaploginCall.getString("code"), "验证code");
			Logger.verifyNotEquals(token, wxwaploginCall.getToken(), "验证新生成的token");
			Thread.sleep(500);
			Map sign=AuthCallServiceV2.signAuth(wxwaploginCall.getToken());
//			Logger.comment(sign.toString());
			Logger.verifyEquals(userId, sign.get("userId"), "验证token-UserId");
			Logger.verifyEquals(userId, wxwaploginCall.getUserId(), "验证UserId");
			Logger.verifyEquals(regbean.getLoginId(), wxwaploginCall.getLoginId(), "验证LoginId");
			JUserWapper JUserWapper=new JUserWapper();
			List<ThirdpartyUserbind> list = JUserWapper.selectthirdpartyuserbind(userId).stream().filter(tu->{return tu.getAppSource()==AppSourceEnum.GlobalWxWap.getCode();}).collect(Collectors.toList());
			Logger.verifyEquals(1, list.size(), "验证有绑定记录");
			Logger.debug(FormatUtil.beanToGSONString(list));
			Logger.verifyEquals(AppSourceEnum.GlobalWxWap.getCode(), list.get(0).getAppSource(), "验证AppSource");
			Logger.verifyEquals(wxwaploginBean.getUnionId(), list.get(0).getThirdPartyId(), "验证thirdPartyId");
			Logger.verifyEquals(wxwaploginBean.getOpenId(), list.get(0).getOpenId(), "验证openId");
			Logger.verifyEquals(6, list.get(0).getThirdPartyType(), "验证thirdPartyType");
			Logger.verifyEquals(userId, list.get(0).getUserId(), "验证userId");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_WxWapLogin_008() {
		Logger.start(true,"同一个uid用2个手机号登入,第二次登入不会记录绑定关系(后续uid登入只会进入第一个账号)");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer userId=registerResult.get("UserId").getAsInt();
			
			
			UserRegisterInfoRequestDtoBean regbean2 = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc2 = JUserCallService.UserRegisterInfoRequestDtoCall(regbean2);
			
			JsonObject registerResult2 = urrc2.getJsonObject().get("Result").getAsJsonObject();
			String token2=registerResult2.get("Token").getAsString();
			Integer userId2=registerResult2.get("UserId").getAsInt();
			//第一次绑定
			wxwaploginBean.setClientIp(regbean.getClientIp());
			wxwaploginBean.setDeviceId(regbean.getDeviceId());
			wxwaploginBean.setMobile(regbean.getLoginMobile());
			wxwaploginBean.setOpenId("oid"+TestDataManager.getRandomIntNum(8));
			wxwaploginBean.setTerminalSource(TerminalSourceEnum.Android.getCode());
			wxwaploginBean.setUnionId("uid"+TestDataManager.getRandomIntNum(8));
			wxwaploginCall.setData(wxwaploginBean);
			wxwaploginCall.callService();	
			Logger.verifyEquals("200", wxwaploginCall.getString("code"), "验证code");
			wxwaploginBean.setMobile(regbean2.getLoginMobile());
			wxwaploginCall.callService();	
			Logger.verifyEquals("200", wxwaploginCall.getString("code"), "验证code");
			
			Logger.verifyNotEquals(token, wxwaploginCall.getToken(), "验证新生成的token");
			Map sign=AuthCallServiceV2.signAuth(wxwaploginCall.getToken());
//			Logger.comment(sign.toString());
			Logger.verifyEquals(userId2, sign.get("userId"), "验证token-UserId");
			Logger.verifyEquals(userId2, wxwaploginCall.getUserId(), "验证UserId");
			Logger.verifyEquals(regbean2.getLoginId(), wxwaploginCall.getLoginId(), "验证LoginId");
			JUserWapper JUserWapper=new JUserWapper();
			List<ThirdpartyUserbind> list = JUserWapper.selectthirdpartyuserbind(userId).stream().filter(tu->{return tu.getAppSource()==AppSourceEnum.GlobalWxWap.getCode();}).collect(Collectors.toList());
			Logger.verifyEquals(1, list.size(), "验证有绑定记录");
			Logger.debug(FormatUtil.beanToGSONString(list));
			Logger.verifyEquals(AppSourceEnum.GlobalWxWap.getCode(), list.get(0).getAppSource(), "验证AppSource");
			Logger.verifyEquals(wxwaploginBean.getUnionId(), list.get(0).getThirdPartyId(), "验证thirdPartyId");
			Logger.verifyEquals(wxwaploginBean.getOpenId(), list.get(0).getOpenId(), "验证openId");
			Logger.verifyEquals(6, list.get(0).getThirdPartyType(), "验证thirdPartyType");
			Logger.verifyEquals(userId, list.get(0).getUserId(), "验证userId");
			list = JUserWapper.selectthirdpartyuserbind(userId2).stream().filter(tu->{return tu.getAppSource()==AppSourceEnum.GlobalWxWap.getCode();}).collect(Collectors.toList());
			Logger.verifyEquals(0, list.size(), "验证无绑定记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_WxWapLogin_010() {
		Logger.start(true,"不输入clientip失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer userId=registerResult.get("UserId").getAsInt();
			BindWeiXinUseroRequestDtoBean bean=JUserCallService.initBindWeiXinUseroRequestDtoBean(token);
			bean.getWeiXinUser().setRegSource(AppSourceEnum.App);
			BindWeiXinUseroRequestDtoCall wx = JUserCallService.bindWeiXinUseroRequestDto(bean);
			
//			wxwaploginBean.setClientIp(regbean.getClientIp());
			wxwaploginBean.setDeviceId(regbean.getDeviceId());
//			wxwaploginBean.setMobile(regbean.getLoginMobile());
			wxwaploginBean.setOpenId(bean.getWeiXinUser().getOId());
			wxwaploginBean.setTerminalSource(TerminalSourceEnum.Android.getCode());
			wxwaploginBean.setUnionId(bean.getWeiXinUser().getUnionId());
			wxwaploginCall.setData(wxwaploginBean);
			wxwaploginCall.callService();	
			Logger.verifyEquals("400", wxwaploginCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_WxWapLogin_011() {
		Logger.start(true,"不输入DeviceId失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer userId=registerResult.get("UserId").getAsInt();
			BindWeiXinUseroRequestDtoBean bean=JUserCallService.initBindWeiXinUseroRequestDtoBean(token);
			bean.getWeiXinUser().setRegSource(AppSourceEnum.App);
			BindWeiXinUseroRequestDtoCall wx = JUserCallService.bindWeiXinUseroRequestDto(bean);
			
			wxwaploginBean.setClientIp(regbean.getClientIp());
//			wxwaploginBean.setDeviceId(regbean.getDeviceId());
//			wxwaploginBean.setMobile(regbean.getLoginMobile());
			wxwaploginBean.setOpenId(bean.getWeiXinUser().getOId());
			wxwaploginBean.setTerminalSource(TerminalSourceEnum.Android.getCode());
			wxwaploginBean.setUnionId(bean.getWeiXinUser().getUnionId());
			wxwaploginCall.setData(wxwaploginBean);
			wxwaploginCall.callService();	
			Logger.verifyEquals("400", wxwaploginCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_WxWapLogin_012() {
		Logger.start(true,"不输入OpenId失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer userId=registerResult.get("UserId").getAsInt();
			BindWeiXinUseroRequestDtoBean bean=JUserCallService.initBindWeiXinUseroRequestDtoBean(token);
			bean.getWeiXinUser().setRegSource(AppSourceEnum.App);
			BindWeiXinUseroRequestDtoCall wx = JUserCallService.bindWeiXinUseroRequestDto(bean);
			
			wxwaploginBean.setClientIp(regbean.getClientIp());
			wxwaploginBean.setDeviceId(regbean.getDeviceId());
//			wxwaploginBean.setMobile(regbean.getLoginMobile());
//			wxwaploginBean.setOpenId(bean.getWeiXinUser().getOId());
			wxwaploginBean.setTerminalSource(TerminalSourceEnum.Android.getCode());
			wxwaploginBean.setUnionId(bean.getWeiXinUser().getUnionId());
			wxwaploginCall.setData(wxwaploginBean);
			wxwaploginCall.callService();	
			Logger.verifyEquals("400", wxwaploginCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_WxWapLogin_013() {
		Logger.start(true,"不输入TerminalSource失败");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer userId=registerResult.get("UserId").getAsInt();
			BindWeiXinUseroRequestDtoBean bean=JUserCallService.initBindWeiXinUseroRequestDtoBean(token);
			bean.getWeiXinUser().setRegSource(AppSourceEnum.App);
			BindWeiXinUseroRequestDtoCall wx = JUserCallService.bindWeiXinUseroRequestDto(bean);
			
			wxwaploginBean.setClientIp(regbean.getClientIp());
			wxwaploginBean.setDeviceId(regbean.getDeviceId());
//			wxwaploginBean.setMobile(regbean.getLoginMobile());
			wxwaploginBean.setOpenId(bean.getWeiXinUser().getOId());
//			wxwaploginBean.setTerminalSource(TerminalSourceEnum.Android.getCode());
			wxwaploginBean.setUnionId(bean.getWeiXinUser().getUnionId());
			wxwaploginCall.setData(wxwaploginBean);
			wxwaploginCall.callService();	
			Logger.verifyEquals("400", wxwaploginCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_WxWapLogin_014() {
		//201908 渠道变更 GlobalWxWap
		Logger.start(true,"手机号已存在微信公众号登录（全球优选）,成功-oid和uid变更会刷新数据库数据");
		try {
			////这里逻辑和Tc_ThirdpartyLogin_051类似 全球优选更换开放平台 登入的时候遇到ThirdPartyId-unionid 不一致 直接更新
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			Integer userId=registerResult.get("UserId").getAsInt();
			BindWeiXinUseroRequestDtoBean bean=JUserCallService.initBindWeiXinUseroRequestDtoBean(token);
			bean.getWeiXinUser().setRegSource(AppSourceEnum.GlobalWxWap);
			BindWeiXinUseroRequestDtoCall wx = JUserCallService.bindWeiXinUseroRequestDto(bean);
			JUserWapper JUserWapper=new JUserWapper();
			List<ThirdpartyUserbind> list = JUserWapper.selectthirdpartyuserbind(userId).stream().filter(tu->{return tu.getAppSource()==AppSourceEnum.GlobalWxWap.getCode();}).collect(Collectors.toList());
			Logger.verifyEquals(1, list.size(), "验证有绑定记录");
			
			
			wxwaploginBean.setClientIp(regbean.getClientIp());
			wxwaploginBean.setDeviceId(regbean.getDeviceId());
			wxwaploginBean.setMobile(regbean.getLoginMobile());
			wxwaploginBean.setOpenId(TestDataManager.getRandomUUID().toString());
			wxwaploginBean.setTerminalSource(TerminalSourceEnum.Android.getCode());
			wxwaploginBean.setUnionId(TestDataManager.getRandomUUID().toString());
			wxwaploginCall.setData(wxwaploginBean);
			wxwaploginCall.callService();	
			Logger.verifyEquals("200", wxwaploginCall.getString("code"), "验证code");
			Logger.verifyNotEquals(token, wxwaploginCall.getToken(), "验证新生成的token");
			Map sign=AuthCallServiceV2.signAuth(wxwaploginCall.getToken());
//			Logger.comment(sign.toString());
			Logger.verifyEquals(userId, sign.get("userId"), "验证token-UserId");
			Logger.verifyEquals(userId, wxwaploginCall.getUserId(), "验证UserId");
			Logger.verifyEquals(regbean.getLoginId(), wxwaploginCall.getLoginId(), "验证LoginId");
			list = JUserWapper.selectthirdpartyuserbind(userId).stream().filter(tu->{return tu.getAppSource()==AppSourceEnum.GlobalWxWap.getCode();}).collect(Collectors.toList());
			Logger.verifyEquals(1, list.size(), "验证有绑定记录");
			Logger.debug(FormatUtil.beanToGSONString(list));
			Logger.verifyEquals(AppSourceEnum.GlobalWxWap.getCode(), list.get(0).getAppSource(), "验证AppSource");
			Logger.verifyEquals(wxwaploginBean.getUnionId(), list.get(0).getThirdPartyId(), "验证thirdPartyId");
			Logger.verifyEquals(wxwaploginBean.getOpenId(), list.get(0).getOpenId(), "验证openId");
			Logger.verifyEquals(6, list.get(0).getThirdPartyType(), "验证thirdPartyType");
			Logger.verifyEquals(userId, list.get(0).getUserId(), "验证userId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	//20190904 增加WxWapLogin 注册流程
	public void Tc_WxWapLogin_015() {
//		Logger.start(true,"输入uid和手机号都不存在,登入失败");
		Logger.start(true,"输入uid不存在手机号为空,失败-手机号必填");
		try {
			
//			String moblie = TestDataManager.getPhoneNum();
//			if (JUserCallService.mobileExists(moblie)) {
//				moblie = TestDataManager.getPhoneNum();
//			}
			
			wxwaploginBean.setClientIp(TestDataManager.getRandomUUID().toString());
			wxwaploginBean.setDeviceId(TestDataManager.getRandomUUID().toString());
//			wxwaploginBean.setMobile(moblie);
			wxwaploginBean.setOpenId("oid"+TestDataManager.getRandomNum(8));
			wxwaploginBean.setTerminalSource(TerminalSourceEnum.Android.getCode());
			wxwaploginBean.setUnionId("uid"+TestDataManager.getRandomNum(8));
			wxwaploginCall.setData(wxwaploginBean);
			wxwaploginCall.callService();	
			Logger.verifyEquals("5000", wxwaploginCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}